/*
	Header!!!!!


*/

/*
REFERENCE:
	int sys_req  ( int op_code,	    {READ,WRITE,CLEAR,GOTOXY,IDLE,EXIT}
			       int device_id,	{TERMINAL, COM_PORT}
			       char *buf_p,		{the from/to buffer}
			       int *count_p		{length of buffer}
		      );

*/

#include "mpx_supt.h"
#include "r1code.h"

int main(){
	sys_init(MODULE_R1); //initialize system, defined in mpx_supt.h
	comhan();
	sys_exit(); //tear down, defined in mpx_supt.h
	return 0;
}

void comhan(){
	int exit = FALSE, numComs = 0;
	printf(
			"\nHello and welcome!\n"
			"Type in a command, and I will blow your mind...\n"
			"Commands:  CHDATE DATE EXIT HELP LS VERSION\n"
		);
	command commands[5] = 
	{
		{help},
		{version},
		{date},
		{dir},
		//{exec},
		{exit}
	};
	
	
	while(!exit){
		char next[100];
		int buffsize=100;
		printf("> ");
		sys_req(READ,TERMINAL,next,&buffsize);
		capitalize(next);
		if(strcmp(next,"HELP\n")==0) printf("There's no help for you!\n");
		else if(strcmp(next,"VERSION\n")==0) printf("Version 1.0.yourmom\n");
		else if(strcmp(next,"DATE\n")==0) printf("It's NOW!\n");
		else if(strcmp(next,"CHDATE\n")==0) printf("You can't change the date, fool!\n");
		else if(strcmp(next,"LS\n")==0) printf("Your directory is as empty as your head!\n");
		else if(strcmp(next,"EXIT\n")==0) exit = TRUE;
		else printf("What is this %s of which you speak?\n",next);
		if(++numComs > 10) {
			printf("I'm tired, so I'm leaving you now.\n");
			exit = TRUE;
		}
	}
}

void capitalize(char* strPtr){
	int i, sLen = strlen(strPtr);
	for(i = 0; i<sLen; i++){
		strPtr[i] = toupper(strPtr[i]);
	}	
}
